package com.qf.day05;

import java.util.Random;

/**
 *
 * 为了在计算中表示一个学生对象
 *
 * 学生类
 * 编写类时，注意，类名的首字母一定要大些
 * 类中可以写属性和方法
 *
 * 学生的属性：姓名，性比，年龄，身高，体重，肤色，学习时长，代码行数，心情值
 * 学生的行为：跑步，吃饭，睡觉，玩游戏，写代码，上课
 */
public class Student {

    public Student(){
//        System.out.println("开始创建Student对象");
        // 给性别赋值为男
        sex = "男";
    }

    public Student(String name){
        this.name = name;
    }


    public Student(String name,String sex,int age,double height,double weight,String color){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.height = height;
        this.weight = weight;
        this.color = color;
    }

    public Student(String name, int age, double height, double weight) {
        this.name = name;
        this.age = age;
        this.height = height;
        this.weight = weight;
    }


    public Student(String name, String sex, int age,double height, double weight, int studyHours, int codeLineNum) {
        // 调用 单参的构造方法 Student(String name)
//        this(name);
        this(name,age,height,weight);  // 可以使用this调用已经存在的构造方法
        this.sex = sex;
        this.studyHours = studyHours;
        this.codeLineNum = codeLineNum;
    }

    // alt + insert
    public Student(String name, String sex, int age, double height, double weight, String color, int studyHours, int codeLineNum, int happy, int devAbility) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.height = height;
        this.weight = weight;
        this.color = color;
        this.studyHours = studyHours;
        this.codeLineNum = codeLineNum;
        this.happy = happy;
        this.devAbility = devAbility;
    }

    String name;

    String sex;

    int age;

    double height;

    double weight;

    String color = "yellow";

    int studyHours;

    int codeLineNum;

    int happy;

    int devAbility;  // 开发能力

    public void run(){
        int weight = 100; // 声明一个跟实例变量同名的局部变量
        Random random = new Random();
        int time = 1+random.nextInt(60);
        System.out.println(name+"在跑步,跑了"+time+"分钟");
        this.weight = this.weight - 1; // 跑步减轻体重
        happy = happy +1; // 跑步增加心情值
        System.out.println("体重为:"+this.weight+",心情为"+happy);
    }

    public void playGame(){
        Random random = new Random();
        int time = 1+random.nextInt(60);
        if (time>30){
            devAbility = devAbility -10;
            happy = happy -10;
            System.out.println(name+"玩游戏,玩太久了，很内疚，心情之为"+happy+"开发能力为:"+devAbility);
        }else {
            happy = happy+10;
            System.out.println("小玩怡情，心情之为"+happy);
        }
    }

    // 方法的重载,只要参数列表能有差异就行
    public void playGame(int minutes){
        if (minutes>60){
            this.happy = this.happy - 20;
            System.out.println(name+"玩太久了，后悔了，心情值为"+happy);
        }else {
            this.happy = this.happy + 10;
            System.out.println(name+"开心了，心情为"+happy);
        }
    }

    /**
     * 重载方法，跟同学一起玩游戏
     * @param minutes 游戏时长
     * @param player  同学对象
     */
    public void playGame(int minutes,Student player){

        if (minutes>60){
            // 让两个同学的都内疚
            this.happy = this.happy - 20;
            System.out.println(name+"玩太久了，后悔了，心情值为"+happy);

            player.happy = player.happy - 30;
            System.out.println(player.name+"玩太久了，更内疚，心情值为"+player.happy);

        }else {
            this.happy = this.happy + 10;
            System.out.println(name+"开心了，心情为"+happy);
            player.happy = player.happy+20;
            System.out.println(player.name+"开心了，心情为"+player.happy);
        }

    }

    /**
     * 增加代码行数
     * @param number
     */
    public void addLineCode(int number){
        this.codeLineNum = this.codeLineNum+number;
    }

    public void study(){
        System.out.println(name+"在学习");
//        this.addLineCode(100);  // this可以调用实例方法
        this.addLineCode(100);  // this可以调用实例方法
    }


//    // student.playGame("tong","超级蛮力");
//    public void playGame(String name,String gameName){
//
//    }
//
//    // student.playGame("超级蛮力","任天堂");
//    public void playGame(String gameName,String company){
//
//    }

}
